package com.sheledon.flyCat.core.aop.intercept;

import com.sheledon.flyCat.core.aop.factory.InterceptFactory;

import java.util.List;

public abstract class AbstractAopProcessor implements BeanProcessor{

    @Override
    public Object postProcessAfterInitialization(Object bean) {
        List<Interceptor> interceptors = InterceptFactory.getInterceptors();
        Object beanInstance = bean;
        for (Interceptor interceptor : interceptors) {
            if (interceptor.supports(bean)){
                beanInstance = wrapBean(beanInstance,interceptor);
            }
        }
        return beanInstance;
    }

    abstract Object wrapBean(Object bean,Interceptor interceptor);
}
